$(document).ready(function() {
  //( Points Remaining / ( points per hour * (( percentual /100)+1)))*3600000
  
  // Science
  var r = $('#awplus_content table:eq(0) tr td:eq(4)').text().match(/([-+0-9]+)/g);

  if (r.length > 1) {
    var science_per = parseInt(r[0]) * ((parseInt(r[1])/100)+1);
    $('table:eq(2) tr td:eq(4)').append(' &nbsp;= '+Math.floor(science_per));
  } else {
    var science_per = parseInt(r[0]);
  }
  
  // Culture
  var x = $('#awplus_content table:eq(0) tr:eq(8) td:eq(0)').text().match(/([-+0-9]+)/g);
  
  if (x.length > 1) {
    var culture_per = parseInt(x[0]) * ((parseInt(x[1])/100)+1);
    $('table:eq(2) tr:eq(8) td:eq(0)').append(' &nbsp;= '+Math.floor(culture_per));
  } else {
    var culture_per = parseInt(x[0]);
  }

  var xd, rmn, rph;
  xd = [];
  $('tr[bgcolor="#206060"] td:eq(3), tr:eq(9) td:eq(3)', 'table:eq(2)').each(function(i) {
    rmn = parseFloat($('input', this).size() ? $('input', this).val() : $(this).text());

    rph = i == 0 ? science_per : culture_per;

    var d = new Date();
    d.setTime(d.getTime() + ((rmn/rph) * 3600000));

    xd.push(d.toString());
    delete d;
  });

  $('#awplus_content table:eq(0)').after('<div id="nla" style="font-size: 0.8em"><br /><b>Next level at:</b><br /><b>Science:</b> '+xd[0]+'<br /><b>Culture:</b> '+xd[1]+'</div>');

});
